package com.nerve.cloudoffice.domain.dao;

import org.nerve.util.FormatUtil;

import com.nerve.cloudoffice.domain.TrashApply;
import com.nerve.cloudoffice.domain.User;

/**
 * @project: cloudOffice
 * @file: TrashApplyDao.java
 * @package: com.nerve.cloudoffice.domain.dao
 * @description:
 *
 * @author: 集成显卡	1053214511@qq.com
				IBM GDC, zengxm@cn.ibm.com
 * @date&time: 2013-8-4
 * @change log:
 */
public class TrashApplyDao extends SuperDAO<TrashApply>{

	/**
	 * @method name: pass
	 * @description: 通过指定id的删除申请，此时，
	 * @return type: void
	 *	@param id
	 */
	public void pass(User passer, int id) throws Exception{
		TrashApply apply = getById(id);
		FormatUtil.notNull(apply, "找不到指定的TrashApply对象，id=" + id);
		
		if(apply.isAgree())
			throw new RuntimeException("此删除申请已经通过！不能再操作");
		
		session.beginTransaction();
		session.createQuery("UPDATE TrashApply SET agree=1, passer_id=" + passer.getId() +" where id="+id).executeUpdate();
		session.createQuery("UPDATE Task SET trash=1 WHERE id="+apply.getTask().getId()).executeUpdate();
		commit();
	}
}
